Merged [21385]:Don't add the musical note to the now-playing status on gadu-gadu...
[adiumx.git] / Plugins / Purple Service / ESPurpleGaduGaduAccount.m
blobdf153721325d8e84df6f8af7ea8ac4cfd5e7f5ff
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "ESPurpleGaduGaduAccountViewController.h"
18 #import "ESPurpleGaduGaduAccount.h"
19 #import <Adium/AIStatusControllerProtocol.h>
20 #import <Adium/AIAccountControllerProtocol.h>
21 #import <Adium/AIListContact.h>
22 #import <Adium/AIStatus.h>
23 #import <Libpurple/gg.h>
24 #import <Libpurple/buddylist.h>
26 #import <AIUtilities/AIAttributedStringAdditions.h>
27 #import <AIUtilities/AIStringAdditions.h>
29 #define MAX_GADU_STATUS_MESSAGE_LENGTH 70
31 @interface ESPurpleGaduGaduAccount (PRIVATE)
32 - (NSAttributedString *)statusMessageForContact:(AIListContact *)theContact;
33 @end
35 @implementation ESPurpleGaduGaduAccount
37 - (const char*)protocolPlugin
39     return "prpl-gg";
42 - (NSString *)connectionStringForStep:(int)step
44         switch (step)
45         {
46                 case 0:
47                         return AILocalizedString(@"Connecting",nil);
48                         break;
49                 case 1:
50                         return AILocalizedString(@"Looking up server",nil);
51                         break;
52                 case 2:
53                         return AILocalizedString(@"Reading data","Connection step");
54                         break;                  
55                 case 3:
56                         return AILocalizedString(@"Balancer handshake","Connection step");
57                         break;
58                 case 4:
59                         return AILocalizedString(@"Reading server key","Connection step");
60                         break;
61                 case 5:
62                         return AILocalizedString(@"Exchanging key hash","Connection step");
63                         break;
64         }
65         return nil;
68 - (void)uploadContactListToServer
70         char *buddylist = ggp_buddylist_dump(account);
71                 
72         if (buddylist) {
73                 PurpleConnection *gc = account->gc;
74                 GGPInfo *info = gc->proto_data;
75                 
76                 AILog(@"Uploading gadu-gadu list...");
77                 
78                 gg_userlist_request(info->session, GG_USERLIST_PUT, buddylist);
79                 g_free(buddylist);
80         }
83 - (void)moveListObjects:(NSArray *)objects toGroup:(AIListGroup *)group
85         [super moveListObjects:objects toGroup:group];
86         
87         [self uploadContactListToServer];
90 - (void)addContacts:(NSArray *)objects toGroup:(AIListGroup *)group
92         [super addContacts:objects toGroup:group];      
93         
94         [self uploadContactListToServer];
97 - (void)removeContacts:(NSArray *)objects
99         [super removeContacts:objects];
100         
101         [self uploadContactListToServer];
104 - (void)downloadContactListFromServer
106         //If we're connected and have no buddies, request 'em from the server.
107         PurpleConnection *gc = account->gc;
108         GGPInfo *info = gc->proto_data;
109         
110         AILog(@"Requesting gadu-gadu list...");
111         gg_userlist_request(info->session, GG_USERLIST_GET, NULL);      
114 - (void)accountConnectionConnected
116         [self downloadContactListFromServer];
118         [super accountConnectionConnected];
121 #pragma mark Status
123  * @brief Encode an attributed string for a status type
125  */
126 - (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forStatusState:(AIStatus *)statusState
128         NSString        *messageString = [[inAttributedString attributedStringByConvertingLinksToStrings] string];
129         return [messageString stringWithEllipsisByTruncatingToLength:MAX_GADU_STATUS_MESSAGE_LENGTH];
132 - (BOOL)handleOfflineAsStatusChange
134         return YES;
138  * @brief Should we add a musical note when indicating a now playing status?
139  * The note doesn't come out properly on Gadu-Gadu, presumably due to encoding issues.
140  */
141 - (BOOL)shouldAddMusicalNoteToNowPlayingStatus
143         return NO;
146 #pragma mark Contact status
148 - (BOOL)shouldAttemptReconnectAfterDisconnectionError:(NSString **)disconnectionError
150         BOOL shouldAttemptReconnect = YES;
151         
152         if (disconnectionError && *disconnectionError) {
153                 if ([*disconnectionError rangeOfString:@"Authentication failed"].location != NSNotFound) {
154                         [self serverReportedInvalidPassword];
155                 }
156         }
157         
158         return shouldAttemptReconnect;
161 #pragma mark Menu Actions
163 - (NSString *)titleForAccountActionMenuLabel:(const char *)label
165         /* These are dumb and should be handled automatically */
166         if (strcmp(label, "Download buddylist from Server") == 0) return nil;
167         if (strcmp(label, "Upload buddylist to Server") == 0) return nil;
168         if (strcmp(label, "Delete buddylist from Server") == 0) return nil;
170         return [super titleForAccountActionMenuLabel:label];
173 @end